package leetcode325;

/**
 * @author aodre , QQ : 480029069
 * @date 2022/12/25 13:39
 */
public class leetcode6269环形字符串 {


    public  int solution(String words[],int start,String target){
        int len = words.length;
        int ans = len,temp = 0;
        for(int i = start,j = 0;j < len;j++){
            temp++;
            if(words[i].equals(target)){
                ans = Math.min(ans,temp);
            }
            i = (i + 1) % len;
        }
        temp = 0;
        for(int i = start,j = 0;j < len;j++){
            temp++;
            if(words[i].equals(target)){
                ans = Math.min(ans,temp);
            }
            i = (i - 1 + len) % len;
        }
        return ans == len ? -1 :  ans;
    }
    /*
        666
        最优解的存在！
     */
    public int closetTarget(String[] words, String target, int startIndex) {
        for (int i = 0; i < words.length; i++) {
            if (words[(startIndex + i) % words.length].equals(target)
                    || words[(startIndex - i + words.length) % words.length].equals(target)) {
                return i;
            }
        }
        return -1;
    }

}
